home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol104 / wsconv.bas < prev    next >
Encoding:
BASIC Source File  |  1986-12-15  |  7.6 KB  |  133 lines

  1. 2 ' $TITLE:'WSCONV.BAS -- WSCONV.EXE (Orig:WS-DOS)' $SUBTITLE:'CONVERTS WORDSTAR& ASCII FILES, ONE TO THE OTHER.' $LINESIZE: 97 $PAGESIZE: 63   Compiler: /o/e
  2. 4 ' BY ANDREW FLUEGELMAN: (C)1983 The Headlands Press.
  3. 6 ' Modified by Jim Gainsley, Mpls.,MN. (c)1983  (Added in L1070:'OR L$="" and      L2125 'PRINT #2,L$.  First to provide hard cr for blank lines. 2nd to write     last line to file if no cr. Also, Choice for Soft & Hard CRLF on AS->WS.
  4. 8 QST$="  ? in response to request for filename gives files on default drive.             You may also use any Basic filename call commands.  To exit after               filename is requested, press ENTER.  WILL OVERWRITE EXISTING FILES!
  5. 10 DEFINT A-Z:ON ERROR GOTO 9000
  6. 15 A=0:A$="":L$="":P=0:ST=0   'Optimizes key variables
  7. 20 CRLF$=CHR$(13)+CHR$(10):HBLF$=CHR$(141)+CHR$(10)  ' Hard & Soft CR/LF
  8. 25 SP$=CHR$(32):TB$=CHR$(9) ' Space & Tab
  9. 30 SH$=CHR$(31):PB$=CHR$(20) ' Soft hyphen & placebo
  10. 35 DT=19:DIM D$(19): FOR P=1 TO DT: READ D$(P):NEXT 'Read dot commands
  11. 40 EN=4: DIM EN(4),ENO$(4),ENC$(4),MRK(4) 'Read enhancement symbols
  12. 45 FOR P=1 TO EN: READ EN(P),ENO$(P),ENC$(P):MRK(P)=0:NEXT
  13. 50 KEY OFF:CLS
  14. 60 LOCATE 10,5:COLOR 15,0:PRINT"PROGRAM TO CONVERT WORDSTAR FILES TO ASCII AND ASCII FILE TO WORDSTAR.":PRINT:LOCATE ,5
  15. 80 PRINT"Original program by Andrew Fleugelman, with extensions by Jim Gainsley":LOCATE ,4:PRINT"Copyright 1983, 1984. Licensed for distribution as Public Domain Software.":PRINT: PRINT
  16. 82 PRINT SPC(15)"...ah let's see... yeah, this is version 2.0":SOUND 32000,30:SOUND 32000,1:COLOR 7,0:CLS
  17. 103 PRINT QST$:PRINT:PRINT
  18. 105 PRINT"                 ======== CONVERT ========
  19. 110 PRINT
  20. 115 PRINT"                  1 - ASCII  to  WORDSTAR
  21. 120 PRINT"                  2 - WORDSTAR  to  ASCII
  22. 900 PRINT"                           X = exit
  23. 905 PRINT
  24. 910 BYT#=0:LOCATE ,10:PRINT"Choose: ";
  25. 915 INPUT "",Q$: IF Q$="x" OR Q$="X" THEN SYSTEM
  26. 920 ON VAL(Q$) GOTO 1000,2000
  27. 925 BEEP:GOTO 103
  28. 930 '
  29. 1000 CLS
  30. 1003 PRINT QST$:PRINT:PRINT
  31. 1005 PRINT"           ==== ASCII-to-WORDSTAR CONVERTER ===="
  32. 1010 PRINT
  33. 1015 PRINT"This routine will convert a standard DOS file into the format
  34. 1020 PRINT"  required by WordStar for paragraph reforming by converting
  35. 1025 PRINT"  'hard' carriage returns (ASCII 13) into 'soft' CR's (ASCII 141).
  36. 1030 PRINT:PRINT"If file contains blank lines between paragraphs or indented
  37. 1035 PRINT"  paragraphs, hard returns will be preserved at each paragraph end.
  38. 1040 PRINT
  39. 1042 PRINT:PRINT"If line FOLLOWING the CURRENT line BEGINS with space(s) or tab(s) then:":PRINT
  40. 1043 PRINT"   1.  Provide Hard CR/LF at end of CURRENT line.
  41. 1044 PRINT"   2.  Provide SOFT CR/LF at end of CURRENT line.
  42. 1045 PRINT:PRINT"  (Note: Option 2 will allow a reformattable structure for indented sections.)":PRINT
  43. 1046 INPUT"       Enter Choice (1/2 [3=exit]): ";ST:IF ST<1 OR ST>3 THEN BEEP:GOTO 1046 ELSE IF ST=2 THEN ST=-1 ELSE IF ST=3 THEN 103
  44. 1048 GOSUB 8000: IF FL$="" THEN 103
  45. 1050 PRINT:PRINT"Conversion in progress...    BYTES PROCESSED:  ";:CS=CSRLIN:        PS=POS(0)
  46. 1055 IF EOF(1) THEN 8045 ELSE LINE INPUT #1,L$  'First line of file only.
  47. 1057 IF EOF(1) AND ST THEN GOSUB 1100
  48. 1060 IF EOF(1) THEN PRINT #2,L$+CRLF$;:GOSUB 1250:GOTO 8045
  49. 1065 LINE INPUT #1,A$
  50. 1070 IF A$="" OR L$="" THEN IF ST AND A$="" AND L$<>"" THEN GOSUB 1100:GOTO 1090     ELSE 1090 'Test for blank line
  51. 1072 IF ST THEN GOSUB 1100:GOTO 1085
  52. 1075 IF LEFT$(A$,2)=SP$+SP$ THEN 1090  ' Test for indent
  53. 1080 IF LEFT$(A$,1)=TB$ THEN 1090 ' Also test for Tab
  54. 1085 PRINT #2,L$+HBLF$;:GOSUB 1250:L$=A$:GOTO 1057  'Write line with soft CR
  55. 1090 PRINT #2,L$+CRLF$;:GOSUB 1250:L$=A$:GOTO 1057  'Write line & hard CR.
  56. 1095 '
  57. 1099 ' Routine to replace spaces 20h with high byte space A0h.
  58. 1100 S$="":S1$="":SL=1
  59. 1110 S$=MID$(L$,SL,1):IF S$<>SP$ THEN 1140
  60. 1120 S1$=S1$+S$:SL=SL+1:GOTO 1110
  61. 1140 IF S1$<>"" THEN FOR J=1 TO LEN(S1$): MID$(L$,J)=CHR$(160):NEXT
  62. 1150 RETURN
  63. 1250 LOCATE CS,PS:BYT#=BYT#+LEN(L$)+2:PRINT BYT#;:RETURN  'Byte counter
  64. 2000 CLS
  65. 2003 PRINT QST$:PRINT:PRINT
  66. 2005 PRINT"           ===== WORDSTAR-to-ASCII CONVERTER =====
  67. 2010 PRINT
  68. 2015 PRINT"This routine converts a WordStar 'Document' file
  69. 2020 PRINT"  into standard DOS format.  All 'high bit' characters
  70. 2025 PRINT"  are converted to their 'low bit' equivalents.
  71. 2030 PRINT"All 'soft' hyphens are stripped, except that any hyphens
  72. 2035 PRINT"  at end of lines are retained.
  73. 2040 PRINT
  74. 2045 PRINT"You can either strip or retain lines that contain dot commands.
  75. 2050 PRINT"As another option, you can either strip all print enhancements
  76. 2055 PRINT"  or replace certain enhancement codes as follows:
  77. 2060 PRINT
  78. 2065 PRINT"        underline (^S) becomes   << ... >>
  79. 2070 PRINT"         boldface (^B) becomes  <<< ... >>>
  80. 2075 PRINT"      superscript (^T) becomes   <^ ... ^>
  81. 2080 PRINT"        subscript (^V) becomes   <_ ... _>
  82. 2085 PRINT
  83. 2090 PRINT :INPUT"Strip or Retain dot commands (s/r): ",Q$
  84. 2095 IF Q$="S" OR Q$="s" THEN STRIPDOT=-1 ELSE STRIPDOT=0
  85. 2100 INPUT"Strip or Replace print enhancements (s/r): ",Q$
  86. 2105 IF Q$="R" OR Q$="r" THEN ENHANCE=-1 ELSE ENHANCE=0
  87. 2110 GOSUB 8000: IF FL$="" THEN 103
  88. 2115 PRINT:PRINT"Conversion in progress...    BYTES PROCESSED:  ";:CS=CSRLIN:        PS=POS(0)
  89. 2120 L$=""
  90. 2125 IF EOF(1) AND L$<>""THEN PRINT #2,L$:BYT#=BYT#+LEN(L$)+2:LOCATE CS,PS:PRINT     BYT#;:GOTO 8045  'Print last file line if no crlf.
  91. 2126 IF EOF(1) THEN 8045 ELSE A$=INPUT$(1,#1):A=ASC(A$):IF A>30 AND A<128 THEN       L$=L$+A$:GOTO 2125 'Soft hyphen or normal ASCII, proceed
  92. 2130 IF A>127 THEN A=A-128:A$=CHR$(A) 'Convert to low-bit character
  93. 2135 IF A>31 THEN L$=L$+A$:GOTO 2125  'Now if normal ASCII, proceed
  94. 2140 IF A=13 THEN GOSUB 2170:A$=INPUT$(1,#1):GOTO 2120'eol, process & remove LF
  95. 2145 IF NOT ENHANCE THEN 2125
  96. 2150 ' Deal with enhancements
  97. 2155 FOR P=1 TO EN:IF A<>EN(P) THEN 2165  'Find special characters
  98. 2160 IF MRK(P) THEN L$=L$+ENC$(P):MRK(P)=0 ELSE L$=L$+ENO$(P):MRK(P)=-1 'Convrt
  99. 2165 NEXT: GOTO 2125
  100. 2170 '  Subroutine to strip soft hyphens and dot commands
  101. 2175 P=INSTR(L$,SH$):IF P=0 OR P>=LEN(L$)-1 THEN 2180 ELSE L$=LEFT$(L$,P-1)+         RIGHT$(L$,LEN(L$)-P):GOTO 2175  'Strip soft hyphens
  102. 2180 IF RIGHT$(L$,1)=SH$ THEN MID$(L$,LEN(L$),1)="-"  'Except at eol
  103. 2185 '
  104. 2190 IF STRIPDOT AND (LEFT$(L$,1)=".") THEN 2200  'Possible dot command?
  105. 2195 PRINT #2,L$:BYT#=BYT#+LEN(L$)+2:LOCATE CS,PS:PRINT BYT#;:RETURN  'Write line to disk.
  106. 2200 B$=MID$(L$,2,1):A=ASC(B$):IF A>64 AND A<91 THEN A=A+32:B$=CHR$(A)
  107. 2205 C$=MID$(L$,3,1):A=ASC(C$):IF A>64 AND A<91 THEN A=A+32:C$=CHR$(A)
  108. 2210 DUMP=0:FOR P=1 TO DT:IF B$+C$=D$(P) THEN DUMP=-1  'Search for dot command
  109. 2215 NEXT: IF DUMP THEN RETURN ELSE GOTO 2195  'Dump line if dot command
  110. 2220 '
  111. 8000 ' File specs
  112. 8005 INPUT"File to Convert:",FL$: IF FL$="" THEN RETURN
  113. 8010 IF LEFT$(FL$,1)="?" THEN GOSUB 8035:GOTO 8005
  114. 8015 OPEN FL$ FOR INPUT AS #1
  115. 8020 INPUT"Convert to file:",FL$: IF FL$="" THEN 8005
  116. 8025 IF LEFT$(FL$,1)="?" THEN GOSUB 8035:GOTO 8020
  117. 8030 OPEN FL$ FOR OUTPUT AS #2: RETURN
  118. 8035 IF LEN(FL$)>1 THEN FL$=RIGHT$(FL$,LEN(FL$)-1) ELSE FL$="*.*"
  119. 8040 PRINT :FILES FL$:PRINT :RETURN
  120. 8045 CLOSE:BEEP:PRINT:PRINT"Done!": GOTO 105
  121. 8050 '
  122. 9000 ' Error trapping
  123. 9005 IF ERL=8015 THEN CLOSE:BEEP:PRINT "==== Filespec Error ====":RESUME 8005
  124. 9010 IF ERL=8030 THEN CLOSE 2:BEEP:PRINT "==== Filespec Error ====":RESUME 8020
  125. 9015 IF ERL=8040 THEN CLOSE:BEEP:PRINT "=== File(s) not Found ===":RESUME 8005
  126. 9020 ON ERROR GOTO 0
  127. 9025 '
  128. 10000 DATA bp,uj,po,cw,ig,cp,fo,fm,he,hm,lh,mb,mt,pa,op,pn,pc,sr,pl
  129. 10005 DATA 19,"<<",">>"
  130. 10010 DATA 2,"<<<",">>>"
  131. 10015 DATA 22,"<_","_>"
  132. 10020 DATA 20,"<^","^>"
  133.